<?php

class M_cetak extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }
 
    public function record_count($dt_start,$dt_end) {
        $SQL_COUNT = "SELECT COUNT(header.id) as total_rec FROM header  LEFT JOIN detail ON header.id = detail.header_id
            WHERE header.Tanggal_COI >= '$dt_start' AND header.Tanggal_COI <= '$dt_end'";
        return $this->db->query($SQL_COUNT)->row()->total_rec;

    }
 
    public function fetch_cetak($limit, $start,$dt_start,$dt_end) {
        //$this->db->limit($limit, $start);
        //$query = $this->db->get("Country");
        //
        $SQL= "SELECT
            header.Importir,
            header.Nomor_Izin_Impor,
            header.Nomor_COI,
            header.Tanggal_COI,
            negara.uraian as Kode_Negara_Muat,
            pelabuhan.uraian as Kode_Pelabuhan_Tujuan,
            detail.Deskripsi_Barang,
            detail.HS,
            detail.Jumlah,
            detail.Satuan,
            detail.nilai_usd,
            header.Kode_Cabang,
            header.Alamat_Importir,
            header.Telp_Importir,
            header.NPWP,
            header.Nomor_API,
            header.Eksportir,
            header.Alamat_Eksportir,
            header.Alamat_Pemeriksaan,
            header.Tanggal_Periksa,
            header.Biaya_Periksa,
            header.Tanggal_Izin_Impor_Exp,
            detail.negara_pembuat,
            header.ql_no,
            header.io_no
            FROM
            header
            INNER JOIN detail ON header.id = detail.header_id
            INNER JOIN pelabuhan ON header.Kode_Pelabuhan_Tujuan = pelabuhan.kode
            INNER JOIN negara ON header.Kode_Negara_Muat = negara.kode
        
            
            WHERE header.Tanggal_COI >= '$dt_start' AND header.Tanggal_COI <= '$dt_end'

            ORDER BY
            header.Tanggal_COI asc, header.Importir asc LIMIT $limit,$start";
        //

        return $this->db->query($SQL);
   }
}